<template>
<client-only>
  <div class="in-wrap">
    <!-- 公共头引入 -->
    <header id="header">
      <section class="container">
        <h1 id="logo">
          <a href="/" title="若毅学堂">
            <img src="~/assets/img/logo.png" width="100%" alt="若毅学堂">
          </a>
        </h1>
        <div class="h-r-nsl">
          <ul class="nav">
            <router-link to="/" tag="li" active-class="current" exact>
              <a>首页</a>
            </router-link>
            <!-- <router-link to="/" custom v-slot="{ navigate }">
              <li class="nuxt-link-exact-active current" @click="navigate" @keypress.enter="navigate" role="link">
                <a>首页</a>
              </li>
            </router-link>
            <router-link to="/course" custom v-slot="{ navigate }">
              <li class="nuxt-link-exact-active current" @click="navigate" @keypress.enter="navigate" role="link">
                <a>课程</a>
              </li>
            </router-link> -->
            <router-link to="/course" tag="li" active-class="current">
              <a>课程</a>
            </router-link>
            <router-link to="/teacher" tag="li" active-class="current">
              <a>名师</a>
            </router-link>
            <!-- <router-link to="/article" tag="li" active-class="current">
              <a>文章</a>
            </router-link>
            <router-link to="/qa" tag="li" active-class="current">
              <a>问答</a>
            </router-link> -->
          </ul>
          <!-- / nav -->
          <ul class="h-r-login">
            <li v-if="!ucenter.id" id="no-login">
              <a href="/sign" title="登录">
                <em class="icon18 login-icon">&nbsp;</em>
                <span class="vam ml5">登录</span>
              </a>
              |
              <a href="/register" title="注册">
                <span class="vam ml5">注册</span>
              </a>
            </li>
            <li v-if="ucenter.id" id="is-login-one" class="mr10">
              <a id="headerMsgCountId" href="#" title="消息">
                <em class="icon18 news-icon">&nbsp;</em>
              </a>
              <q class="red-point" style="display: none">&nbsp;</q>
            </li>
            <li v-if="ucenter.id" id="is-login-two" class="h-r-user">
              <a href="/me" title>
                <img
                  :src="ucenter.avatar"
                  width="30"
                  height="30"
                  class="vam picImg"
                  alt
                  >
                  <span id="userName" class="vam disIb">{{ ucenter.nickname }}</span>
                </a>
                <a href="javascript:void(0);" title="退出" @click="logout()" class="ml5">退出</a>
            </li>
            <!-- /未登录显示第1 li；登录后显示第2，3 li -->
          </ul>
          <aside class="h-r-search">
            <!-- <form action="#" method="post">
              
            </form> -->
            <label class="h-r-s-box">
              <input type="text" placeholder="输入你想学的课程" v-model="queryCourse.courseName">
              <button type="submit" class="s-btn" @click="searchCourse">
                <em class="icon18">&nbsp;</em>
              </button>
            </label>
          </aside>
        </div>
        <aside class="mw-nav-btn">
          <div class="mw-nav-icon"></div>
        </aside>
        <div class="clear"></div>
      </section>
    </header>
    <!-- /公共头引入 -->
      
    <nuxt/>

    <!-- 公共底引入 -->
    <footer id="footer">
      <section class="container">
        <div class>
          <h4 class="hLh30">
            <span class="fsize18 f-fM c-999">友情链接</span>
          </h4>
          <ul class="of flink-list">
            <li>
              <a href="http://121.40.219.144/" title="若毅学堂后台" target="_blank">若毅学堂后台</a>
            </li>
          </ul>
          <div class="clear"></div>
        </div>
        <div class="b-foot">
          <section class="fl col-7">
            <section class="mr20">
              <section class="b-f-link">
                <a href="javascript:void(0)" title="关于我们">关于我们</a>|
                <a href="javascript:void(0)" title="联系我们">联系我们</a>|
                <a href="javascript:void(0)" title="帮助中心">帮助中心</a>|
                <a href="javascript:void(0)" title="资源下载">资源下载</a>|
                <span>服务热线：010-32442313(北京) 0755-31244423(深圳)</span>
                <span>Email：info@ruoyi.com</span>
              </section>
              <section class="b-f-link mt10">
                <span>©2022课程版权均归若毅学堂所有 京ICP备17055252号</span>
              </section>
            </section>
          </section>
          <aside class="fl col-3 tac mt15">
            <section class="gf-tx">
              <span>
                <img src="~/assets/img/wx-icon.png" alt>
              </span>
            </section>
            <section class="gf-tx">
              <span>
                <img src="~/assets/img/wb-icon.png" alt>
              </span>
            </section>
          </aside>
          <div class="clear"></div>
        </div>
      </section>
    </footer>
    <!-- /公共底引入 -->
  </div>
</client-only>
</template>
<script>
import "~/assets/css/reset.css"
import "~/assets/css/theme.css"
import "~/assets/css/global.css"
import "~/assets/css/web.css"
import cookie from 'js-cookie'

export default {
  data() {
    return {
      token: null,
      queryCourse: {
        courseName: ''
      },
      ucenter: {
        id: '',
        age: '',
        avatar: '',
        mobile: '',
        nickname: '',
        sex: ''
      }
    }
  },
  created() {
    this.getLoginInfo()
  },
  methods: {
    getLoginInfo() {
      this.token = cookie.get("user_token")
      const jsonStr = cookie.get("user_ucenter")
      if (jsonStr) {
        this.ucenter = JSON.parse(jsonStr)
      }
      
      // console.log(cookie.get("user_token"))
      // console.log(cookie.get("user_ucenter"))
      // console.log(this.ucenter)

    },
    logout() {
      // debugger
      cookie.set('user_token', "")
      cookie.set('user_ucenter', "")

      //跳转页面
      window.location.href = "/"
    },
    searchCourse() {
      if (this.queryCourse.courseName.length > 0) {
        window.location.href = "/course/search?s="+this.queryCourse.courseName
      }
    }
  }
}
</script>